/*****************************************************************************

File:   otkFamilyTableUtils.java

Date          Build     Author        Version    Comments
12-Oct-12    P-20-14    dshah         $$1       Created


****************************************************************************/
package com.ptc.otkjavaexamples;
 
import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSolid.*;
import com.ptc.wfc.wfcFamily.*;
import com.ptc.wfc.wfcModel.*;
 
// Utility to show/write Family Table info
class otkFamilyTableUtils 
{



    public otkFamilyTableUtils()
	{
	}

	
	public static int OtkUtilFamilyTableInfo(WSolid pFTModel, BufferedWriter infoFile)
	{

		try
		{
			FamilyMember FMemb = (FamilyMember)(pFTModel);
	  		
			FamilyTableRows FTRows = FMemb.ListRows();
	
			int NumberOfRows = FTRows.getarraysize();

			if(NumberOfRows == 0)
			{
				infoFile.write("++ Family table is not found");
				infoFile.newLine();
				return (0);
			}
			infoFile.write("++ Number of instance Rows: " + NumberOfRows);
			infoFile.newLine();

			if(NumberOfRows > 0)
			{
				WSolid wSolid = (WSolid)(pFTModel);
				WFamilyMember FamMemb = (WFamilyMember)(wSolid);

				boolean is_mod_2 = FamMemb.IsModifiable(true);
				infoFile.write("++ Family Member Modifiable: " + (is_mod_2 == true ? "TRUE" : "FALSE"));
				infoFile.newLine();

				for(int i=0; i<NumberOfRows; i++)
				{
					infoFile.write("  ++ Instance: " + (i+1));
					infoFile.newLine();

					FamilyTableRow pThisRow = FTRows.get(i);
					String InstName = pThisRow.GetInstanceName();
			
					infoFile.write("\t++ Instance Name: " + InstName);
					infoFile.newLine();
					WFamilyTableRow wThisRow = (WFamilyTableRow)(pThisRow);
			
					boolean flat = wThisRow.IsFlatState();
					infoFile.write("\t++ Flat State: " +(flat == true ? "TRUE" : "FALSE"));
					infoFile.newLine();

					boolean IsLocked = wThisRow.GetIsLocked();
					infoFile.write("\t++ Is Locked: " +(IsLocked == true ? "TRUE" : "FALSE"));
					infoFile.newLine();

					WModel ModelfromDisk = wThisRow.GetModelFromDisk();
					infoFile.write("\t++ Model from Disk Name: " + ModelfromDisk.GetFullName());
					infoFile.newLine();

					boolean is_mod = wThisRow.IsModifiable(true);
					infoFile.write("\t++ Table Row Modifiable: " +(is_mod == true ? "TRUE" : "FALSE"));
					infoFile.newLine();

					WModel ModelfromSession = wThisRow.GetModelFromSession();
					infoFile.write("\t++ Model from Session Name: " + ModelfromSession.GetFullName());
					infoFile.newLine();
					infoFile.newLine();
				}
			}
		}//try
		catch (Exception e)
		{
			System.out.println("1: " + e);
		}	
		return 0;
	}
	
	// Utility to Erase Family Table
	public static int OtkUtilFamilyTableErase (WSolid wSolid)
	{
		try
		{	
			WFamilyMember FamMemb = (WFamilyMember)(wSolid);

			FamilyTableStatus FTStatus = FamMemb.GetFamilyTableStatus();

			if(FTStatus == FamilyTableStatus.FAMILY_TABLE_VALID_AND_NOT_EMPTY)
				FamMemb.EraseFamilyTable();
		} // try
		catch (Exception e)
		{
			System.out.println("1: " + e);
		}	
		return 0;
	}
	

};






